﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

public class TriggerWaitInput : MonoBehaviour
{
    public KeyCode targetKey = KeyCode.F;
    public string targetTag = "Player";
    public bool isUpdate = false;

    public UnityEvent onInputDown;
    public UnityEvent onInputDownLate;

    bool isInvoke = false;
    bool isStay = false;

    private void OnEnable()
    {
        isInvoke = false;
    }

    private void OnTriggerStay(Collider other)
    {
        if (other.tag == targetTag)
        {
            isStay = true;
        }
    }

    private void Update()
    {
        if (Input.GetKeyDown(targetKey) && isStay && !isInvoke)
        {
            onInputDown?.Invoke();
            onInputDownLate?.Invoke();
            if (!isUpdate)
            {
                isInvoke = true;
            }
        }
    }

    private void FixedUpdate()
    {
        isStay = false;
    }
}
